package com.mjf.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

class MyCallable implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        System.out.println(Thread.currentThread().getName()+" Come in call");
        //睡5秒
        TimeUnit.SECONDS.sleep(5);
        //返回200的状态码
        return 200;

    }
}

public class CreateThreadWithCallable {
    public static void main(String[] args) throws InterruptedException, ExecutionException {

        MyCallable myCallable = new MyCallable();
        FutureTask<Integer> futureTask = new FutureTask<>(myCallable);
        new Thread(futureTask, "未来任务").start();
        System.out.println("主线程结束！");
        Integer integer = futureTask.get();
        System.out.println(integer);

    }
}